package com.fhs.demo.config;

import com.fhs.trans.service.impl.DictionaryTransService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.ConfigurableEnvironment;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: SystemConfig
 * @author: aurong
 * @Date: 2023/11/26 23:00
 * @Version 1.0.0
 */
@Configuration
@Slf4j
//@RequiredArgsConstructor
public class EasyTransConfig {

    @Autowired
    private ConfigurableEnvironment environment;

    @Autowired  //注入字典翻译服务
    private  DictionaryTransService dictionaryTransService;

//    @Bean
//    public DictionaryTransService dictionaryTransService(){
//        log.info("=======init DictionaryTransService =======");
//        return new DictionaryTransService();
//    }

    @PostConstruct
    public void initDict() {
//        dictionaryTransService = this.dictionaryTransService();
        //在某处将字典缓存刷新到翻译服务中，以下是demo
        Map<String,String> transMap = new HashMap<>();
        transMap.put("0","男");
        transMap.put("1","女");
        dictionaryTransService.refreshCache("sex",transMap);
        log.info("初始化字典:{}",transMap);
    }
}
